home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / pbm / pbmtoptx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-06  |  2.0 KB  |  103 lines

  1. /* pbmtoptx.c - read a portable bitmap and produce a Printronix printer file
  2. **
  3. ** Copyright (C) 1988 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include "pbm.h"
  14.  
  15. static void putinit ARGS(( void ));
  16. static void putbit ARGS(( bit b ));
  17. static void putrest ARGS(( void ));
  18. static void putitem ARGS(( void ));
  19.  
  20. void main( argc, argv )
  21. int argc;
  22. char *argv[];
  23.     {
  24.     FILE *ifp;
  25.     register bit *bitrow, *bP;
  26.     int rows, cols, format, row, col;
  27.     char *usage = "[pbmfile]";
  28.  
  29.     pbm_init( &argc, argv );
  30.  
  31.     if ( argc > 2 )
  32.     pm_usage( usage );
  33.  
  34.     if ( argc == 2 )
  35.     ifp = pm_openr( argv[1] );
  36.     else
  37.     ifp = stdin;
  38.  
  39.     pbm_readpbminit( ifp, &cols, &rows, &format );
  40.     bitrow = pbm_allocrow( cols );
  41.  
  42.     putinit( );
  43.     for ( row = 0; row < rows; row++ )
  44.     {
  45.     pbm_readpbmrow( ifp, bitrow, cols, format );
  46.         for ( col = 0, bP = bitrow; col < cols; col++, bP++ )
  47.         putbit( *bP );
  48.     putrest( );
  49.     putchar( 5 );
  50.     putchar( '\n' );
  51.         }
  52.  
  53.     pm_close( ifp );
  54.     
  55.     pm_close (stdout);
  56.  
  57.     exit( 0 );
  58.     }
  59.  
  60. static char item;
  61. static int bitsperitem, bitshift;
  62.  
  63. static void
  64. putinit( )
  65.     {
  66.     bitsperitem = 0;
  67.     item = 64;
  68.     bitshift = 0;
  69.     }
  70.  
  71. #if __STDC__
  72. static void
  73. putbit( bit b )
  74. #else /*__STDC__*/
  75. static void
  76. putbit( b )
  77.     bit b;
  78. #endif /*__STDC__*/
  79.     {
  80.     if ( bitsperitem == 6 )
  81.     putitem( );
  82.     if ( b == PBM_BLACK )
  83.     item += 1 << bitshift;
  84.     bitsperitem++;
  85.     bitshift++;
  86.     }
  87.  
  88. static void
  89. putrest( )
  90.     {
  91.     if ( bitsperitem > 0 )
  92.     putitem( );
  93.     }
  94.  
  95. static void
  96. putitem( )
  97.     {
  98.     putchar( item );
  99.     bitsperitem = 0;
  100.     item = 64;
  101.     bitshift = 0;
  102.     }
  103.